<?php
/**
 * 在网页上产生一个信息框
 * 
 * $Id: message.php 130 2010-10-10 16:47:37Z Administrator $
 * $Revision: 130 $
 * $Author: Administrator $
 * $Date: 2010-10-10 16:47:37 +0000 (Sun, 10 Oct 2010) $
 * 信息提示框可用于Ajax,普通页面等调用
 * 具有倒计时，标题，内容和若干个按键
 * 
 * @author glzaboy<glzaboy@163.com>
 * @package fastlib
 * @subpackage classes
 * @copyright 2005-2010 (c) glzaboy
 */
if (! defined ( '__FASTLIB__' )) {
	if (__DEBUG__) {
		die ( sprintf ( 'Forbidden 403 at file %s on line %d', __FILE__, __LINE__ ) );
	} else {
		die ( 'Forbidden 403' );
	}
}
/**
 * 在网页上输出信息可以使用Ajax方式调用
 *
 **/
class message {
	/**
	 * 信息框标题
	 *
	 * @var string
	 */
	private $caption = "Message";
	/**
	 * 在网页上输出信息可以使用Ajax方式调用
	 *
	 * @param string $message 提示信息，可以使用HTML
	 * @param Array $button 按钮信息
	 * @param string $caption　提示信息标题，可以使用HTML
	 * @param bool $msgtype 取值0(文字),1(按钮),2(返回对话框HTML) 
	 * @param Int $defbtn 默认的按钮
	 * @param Int $auto_time　执行按钮的涵数时间
	 * @return message
	 */
	public function message($message, $button = array(), $caption = "", $msgtype = 0, $defbtn = 0, $auto_time = 10) {
		global $flibcfg;
		if (isset ( $button ['action'] ) || isset ( $button ['url'] ) || isset ( $button ['value'] ) || isset ( $button ['key'] )) {
			$button = array ($button );
		}
		$caption = $caption ? $caption : $this->caption;
		if (isset ( $_GET ['wml'] )) {
			setGetValue ( 'wml', 0, '/^0-9/', 'session', false );
		}
		if (isset ( $_SESSION ['wml'] ) && $_SESSION ['wml'] == 1) {
			if (! function_exists ( 'wmlGroups' )) {
				FastLoad::loadLib ( 'wml', __FILE__, __LINE__ );
			}
			$g = wmlGroups ();
			$card = wmlCard ();
			wmlSetvar ( $card, 'msg', $message );
			wmlSetvar ( $card, "button", $button );
			wmlAddcard ( $g, $card, __FASTTPL__ . 'message.fs', array ('title' => $caption ) );
			wmlOutput ( $g, null, 0 );
			unset ( $card, $g );
		} else {
			setHeader ( 'cache', 0 );
			$tpl = new fasttpl ();
			$tpl->assign ( "caption", $caption );
			setDocTitle ( $caption, "I" );
			setRule ( null, 'CSS', 'C' );
			setRule ( null, 'JS', 'C' );
			if (isset ( $flibcfg ['message'] ['tpl'] ) && is_string ( $flibcfg ['message'] ['tpl'] ) && file_exists ( getSiteCurrent ( true ) . $flibcfg ['message'] ['tpl'] )) {
				$mytpl = getSiteCurrent ( true ) . $flibcfg ['message'] ['tpl'];
				if (isset ( $flibcfg ['message'] ['css'] ) && is_array ( $flibcfg ['message'] ['css'] )) {
					foreach ( $flibcfg ['message'] ['css'] as $v ) {
						$v ['src'] = getSiteCurrent ( false ) . $v ['src'];
						setRule ( $v, 'css', 'a' );
					}
				}
				if (isset ( $flibcfg ['message'] ['js'] ) && is_array ( $flibcfg ['message'] ['js'] )) {
					foreach ( $flibcfg ['message'] ['js'] as $v ) {
						$v ['src'] = getSiteCurrent ( false ) . $v ['src'];
						setRule ( $v, 'js', 'a' );
					}
				}
			} else {
				$mytpl = __FASTTPL__ . 'message.fs';
				setSitecfg ( 'dtd', '4.0t' );
				setRule ( array ('src' => __FASTTPL__ . 'message.css' ), 'fetch', 'a' );
			}
			$tpl->assign ( "msg", $message );
			$tpl->assign ( "button", $button );
			$tpl->assign ( "msgtype", $msgtype );
			$tpl->assign ( "defbtn", $defbtn );
			$tpl->assign ( "auto_time", $auto_time );
			$tpl->display ( $mytpl );
		}
	}
	/**
	 * 返回本模块信息
	 *
	 * @return string
	 */
	public function printInfo() {
		$version = '$Revision: 130 $';
		$moudle = __CLASS__;
		$return = '';
		$return .= startTable ();
		$return .= printRow ( array (array ('class' => 'h', 'content' => '<center>' . $moudle . '</center>', 'colspan' => '2' ) ) );
		$return .= printRow ( array (array ('class' => 'e', 'content' => 'Description' ), array ('class' => 'v', 'content' => 'Create a web or wml page, the user can see information,and choose.' ) ) );
		$return .= printRow ( array (array ('class' => 'e', 'content' => 'author' ), array ('class' => 'v', 'content' => 'glzaboy' ) ) );
		$return .= printRow ( array (array ('class' => 'e', 'content' => 'version' ), array ('class' => 'v', 'content' => $version ) ) );
		$return .= printRow ( array (array ('class' => 'e', 'content' => 'Support' ), array ('class' => 'v', 'content' => 'custom template,wml,wap,ajax' ) ) );
		$return .= printRow ( array (array ('class' => 'e', 'content' => 'Dependence' ), array ('class' => 'v', 'content' => 'fasttpl,smarty' ) ) );
		$return .= endTable ();
		return $return;
	}
}